package com.xdxc.model.enums;


import com.xdxc.exception.CustomException;

public enum ExamStatus {

    IN_PROGRESS(1, "批改正在进行") {
        @Override
        public void handle() {
            throw new CustomException(400,"批改正在进行");
        }
    },
    FINISHED(2, "批改已结束") {
        @Override
        public void handle() {
            throw new CustomException(400,"批改已结束");
        }
    };

    private final int code;
    private final String description;

    ExamStatus(int code, String description) {
        this.code = code;
        this.description = description;
    }

    public int getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    // 抽象方法，每个枚举值必须实现
    public abstract void handle();

    public static ExamStatus fromCode(int code) {
        for (ExamStatus status : values()) {
            if (status.code == code) {
                return status;
            }
        }
        throw new IllegalArgumentException("无效的考试状态码: " + code);
    }
}